t = int(input())
for i in range(t):
n = int(input())
arr1 = list(map(int, input().split(sep = ' ')))
arr2 = list(map(int, input().split(sep = ' ')))
k = abs(arr1.count(1) - arr2.count(1))
cnt = 0
for j in range(n):
if (arr1[j] != arr2[j]):
cnt = cnt + 1
if (arr1 == arr2):
print(0)
elif (arr1.count(1) == arr2.count(1)):
print(1)
else:
print(min(k+1,cnt))
#include <bits/stdc++.h>
using namespace std;
void solve()
{
int n;
cin >> n;
int a[n];
int b[n];
int c01 = 0, c10 = 0;
for (int i = 0; i < n; i++)
{
cin >> a[i];
}
for (int i = 0; i < n; i++)
{
cin >> b[i];
if (a[i] == 0 && b[i] == 1)
c01++;
if (a[i] == 1 && b[i] == 0)
c10++;
}
if (c01 == c10 && c10 == 0)
{
cout << 0 << endl;
return;
}
else if (c01 == c10)
{
cout << 1 << endl;
return;
}
else if (min(c10, c01) == 0)
{
cout << max(c10, c01) << endl;
}
else
{
cout << 1 + abs(c10 - c01) << endl;
}
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--)
solve();
return 0;
}
1506A - Strange Table | 456A - Laptops |
855B - Marvolo Gaunt's Ring | 1454A - Special Permutation |
1359A - Berland Poker | 459A - Pashmak and Garden |
1327B - Princesses and Princes | 1450F - The Struggling Contestant |
1399B - Gifts Fixing | 1138A - Sushi for Two |
982C - Cut 'em all | 931A - Friends Meeting |
1594A - Consecutive Sum Riddle | 1466A - Bovine Dilemma |
454A - Little Pony and Crystal Mine | 2A - Winner |
1622B - Berland Music | 1139B - Chocolates |
1371A - Magical Sticks | 1253A - Single Push |
706B - Interesting drink | 1265A - Beautiful String |
214A - System of Equations | 287A - IQ Test |
1108A - Two distinct points | 1064A - Make a triangle |
1245C - Constanze's Machine | 1005A - Tanya and Stairways |
1663F - In Every Generation | 1108B - Divisors of Two Integers |